<?php

class admin_controller_system_config extends admin_controller
{

    public function system()
	{
		$template = $this->get_admin_template();
		$template->set_title('配置系统参数');
		$template->set('config', bone::get_config('system'));
		$template->display();
	}

	public function system_save()
	{
		$config = bone::get_config('system');
		$config->offline = post('offline', '0');
		$config->offline_message = post('offline_message', '', 'string', false);
		$config->site_url = post('site_url', '');
		$config->site_name = post('site_name', '');
		$config->sef = post('sef', '0');

		$model_config = $this->get_admin_model();
		$model_config->save_to_file($config, BONE_ROOT.DS.'configs'.DS.'system.php');
		
		system_log('配置系统参数');
		
		$this->redirect('./?action=system.config.system', '保存成功');
	}
	
	

	public function mail()
	{
		$config = bone::get_config('mail');

		$template = $this->get_admin_template();
		$template->set_title('配置邮件参数');
		$template->set('config', $config);
		$template->display();
	}

	public function mail_save()
	{
		$config = bone::get_config('mail');

		$config->from_mail = post('from_mail', '');
		$config->from_name = post('from_name', '');
		$config->smtp = post('smtp', '0');
		$config->smtp_host = post('smtp_host', '');
		$config->smtp_port = post('smtp_port', '25');
		$config->smtp_user = post('smtp_user', '');
		$config->smtp_pass = post('smtp_pass', '');

		$model_config = $this->get_admin_model();
		$model_config->save_to_file($config, BONE_ROOT.DS.'configs'.DS.'mail.php');
		
		system_log('配置邮件参数');
		
		$this->redirect('./?action=system.config.mail', '保存成功');
	}

	public function mail_test()
	{
		$template = $this->get_admin_template();
		$template->set_title('发送邮件测试');
		$template->display();
	}

	public function mail_test_save()
	{
		$to_email = post('to_email', '');
		$subject = post('subject', '');
		$body = post('body', '');

		$lib_mail = bone::get_lib('mail');
		$lib_mail->set_subject($subject);
		$lib_mail->set_body($body);
		$lib_mail->to($to_email);

		if( $lib_mail->send() )
		{
            system_log('发送测试邮件到: '.$to_email);
			$this->redirect('./?action=system.config.mail_test&to_email='.$to_email, '发送邮件成功');
		}
		else
			$this->redirect('./?action=system.config.mail_test&to_email='.$to_email, '发送邮件失败: '.$lib_mail->get_error(), 'error');
	}
}
?>